home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 364_01 / exit_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-24  |  6KB  |  196 lines

  1. /*
  2. HEADER:         ;
  3. TITLE:          C-ACROSS;
  4. VERSION         1.02
  5.  
  6. DESCRIPTION:   "Utility for multiple module programs. Produces
  7.       Six indexes of functions, prototypes, and globals that
  8.       enable user to 'see across' modules for use in checking
  9.       and comparison.  One of these is type of hierarchical
  10.       functions list, a listing by module of functions
  11.       and calls made FROM them; another is alphabetical list
  12.       of functions and calls made TO them. Globals listed
  13.       in schematic descriptors which record all modifiers
  14.       and qualifiers and enable checking of declarators
  15.       across modules. Creates, on request, header file
  16.       consisting of prototypes constructed from function
  17.       definitions. Can list user types #defined and some
  18.       preprocessor #defines. Full documentation in README.CA";
  19.  
  20. KEYWORDS:       Utility, Cross Reference, Deubgging;
  21. SYSTEM:         MS-DOS;
  22. FILENAME:       EXIT_CA.C;
  23.  
  24. WARNINGS:      "1. Assumes function definitions conform with
  25.         ANSI standards and have prototype form. See
  26.         also "Caveats and Restrictions" in README.CA.
  27.         2. Assumes syntactically correct source files.
  28.         3. Written and tested using Microsoft QuickC.
  29.         4. Copyright retained.  See Copyright
  30.         information in README.CA.";
  31.  
  32. SEE-ALSO:      EXIT_CA.C, FUNC_CA.C, GLOB_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
  34.            UTLG_CA.C, XRF_CA.C, README.CA,
  35.            CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
  36. AUTHORS:       Myron Turner;
  37. COMPILERS:     Microsoft C;
  38.  
  39. */
  40.  
  41. /* **************************  C-ACROSS  **************************
  42.                    V. 1.02
  43.                Copyright (C) Myron Turner
  44.  
  45.               333 Bartlet Ave.
  46.               Winnipeg, Manitoba
  47.               Canada R3L 0Z9
  48.               (204) 284-8387
  49.  
  50.  ******************************************************************** */
  51.  
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include <stdlib.h>
  55. void nullptrxit(char *msg, char *filename, unsigned lineno);
  56. static void prn_exitmsg(FILE *output, char const *function, char const *module,
  57.             char const *exit_msg, char *exit_str, int exit_code);
  58.  
  59. static const char *exit_msg[] =
  60.  {
  61.    /* IFDEF_CA */
  62.    "cannot inititiate ifdef stack",           /* 0 */
  63.    "cannot continue ifdef stack",             /* 1 */
  64.  
  65.   /* UTLG_CA */
  66.    "cannot initiate user type stack",         /* 2 */
  67.    "cannot continue user type stack",         /* 3 */
  68.  
  69.   /* INTF_CA  */
  70.    "unable to allocate file buffer",          /* 4 */ /* /get_new_path */
  71.    "cannot allocate \"file_string\"",         /* 5 */  /* get_modules */
  72.  
  73.    "problem in command line arguments",       /* 6 */  /* argv_cat */
  74.    "unable to open report file: ",            /* 7 */   /* make_rpt_file */
  75.    "no source files found in project file",   /* 8 */   /* main */
  76.  
  77.   /* XRF_CA  */
  78.    "unable to create binary search array",   /* 9 *//* create_bsearch_array*/
  79.    "Null Pointer Error"                      /* 10 */
  80.    };
  81.  
  82. static const char *FUNCTION[] = {
  83.    "push_ifdef",           /* 0 */
  84.    "push_ifdef",           /* 1 */
  85.    "push_usertype",        /* 2 */
  86.    "push_usertype",        /* 3 */
  87.    "get_new_path",         /* 4 */
  88.    "get_modules",          /* 5 */
  89.    "argv_cat",             /* 6 */
  90.    "make_rptfile",         /* 7 */
  91.    "main",                 /* 8 */
  92.    "create_bsearch_array", /* 9 */
  93.    "xrf"                   /*10*/
  94.    };
  95.  
  96.  
  97. static const char *MODULE[] = {
  98.    "IFDEF_CA",       /* 0 */
  99.    "UTLG_CA",        /* 1 */
  100.    "INTF_CA",        /* 2 */
  101.    "XRF_CA"          /* 3 */
  102.    };
  103.  
  104.  
  105. enum {
  106.     NO_IFDEF_STK, BAD_IFDEF_STK,         /* IFDEF_CA */   /* memory */
  107.  
  108.     NO_USER_TYP_STK, BAD_USER_TYP_STK,   /* UTLG_CA */    /* memory */
  109.  
  110.     BAD_FILE_BUF, NO_FILE_STR,           /* INTF_CA */    /* memory */
  111.     BAD_ARGV,  BAD_FILE, BAD_PROJ,                        /* files  */
  112.  
  113.     NO_BSEARCH_ARRAY,                    /* XRF_CA  */    /* memory */
  114.     NULL_POINTER
  115.     };
  116.  
  117. extern FILE *scrn_out;
  118. void exit_ca(int exit_code, char *exit_str)
  119. {
  120.  
  121.    const char *module = NULL;
  122.    char *ptr;
  123.    size_t pos;
  124.  
  125.        switch (exit_code)
  126.        {
  127.      case NO_IFDEF_STK: case  BAD_IFDEF_STK:
  128.      /* IFDEF_CA */
  129.        module =     MODULE[0];
  130.        break;
  131.  
  132.      case NO_USER_TYP_STK: case BAD_USER_TYP_STK:
  133.        /* UTLG_CA */
  134.        module =     MODULE[1];
  135.        break;
  136.  
  137.      case BAD_FILE_BUF: case NO_FILE_STR: case BAD_ARGV:
  138.      case BAD_FILE:  case BAD_PROJ:
  139.      /* INTF_CA */
  140.        module =     MODULE[2];
  141.        break;
  142.  
  143.      case NO_BSEARCH_ARRAY:
  144.        /* XRF_CA */
  145.        module =     MODULE[3];
  146.        break;
  147.  
  148.      case NULL_POINTER:
  149.        ptr = exit_str;
  150.        pos = strcspn(exit_str, ". ");
  151.        exit_str = strchr(exit_str, ' ');
  152.        *(ptr + pos) = '\0';
  153.        strupr(ptr);
  154.        module = ptr;
  155.        break;
  156.        }
  157.       printf ("\a");
  158.       prn_exitmsg((FILE *)stdout, FUNCTION[exit_code], module,
  159.       exit_msg[exit_code], exit_str, exit_code);
  160.  
  161.       if(scrn_out != (FILE *)stdout)
  162.        prn_exitmsg(scrn_out, FUNCTION[exit_code], module, exit_msg[exit_code],
  163.        exit_str, exit_code);
  164.  
  165.        exit(exit_code);
  166.  
  167.  }
  168.  
  169. static void prn_exitmsg(FILE *output, char const *function, char const *module,
  170.             char const *xit_msg, char *exit_str, int exit_code)
  171. {
  172.  
  173.      fprintf(output, "\n***");
  174.      if (exit_code <= NO_FILE_STR || exit_code == NO_BSEARCH_ARRAY)
  175.        fprintf(output, "Out of memory:\n  ");
  176.  
  177.      if (exit_code != BAD_FILE)
  178.        fprintf(output,"%s\n%s   function: %s()   [module: %s.C]\n",
  179.          xit_msg, exit_str, function, module);
  180.      else
  181.      if (exit_code == BAD_FILE) {
  182.        strupr (exit_str);
  183.        fprintf(output,"%s\"%s\"\n    function: %s()  [module: %s.C]\n",
  184.           xit_msg, exit_str, function, module);
  185.           }
  186. }
  187.  
  188. void nullptrxit(char *msg, char *filename, unsigned lineno)
  189. {
  190.     char buffer[81];
  191.  
  192.   sprintf(buffer, "%s %s:\n  Line: %d",  filename, msg, lineno);
  193.   exit_ca(NULL_POINTER, buffer);
  194. }
  195.  
  196.